package br.com.affero.hibernate;

import br.com.affero.model.bean.Documento;
import br.com.affero.model.bean.Usuario;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtils {

    private static SessionFactory sessionFactory;

    public Session openSession() {
        if (sessionFactory == null) {
            AnnotationConfiguration cfg = new AnnotationConfiguration();
            cfg.addAnnotatedClass(Usuario.class);
            cfg.addAnnotatedClass(Documento.class);
            sessionFactory = cfg.buildSessionFactory();
        }
        return sessionFactory.openSession();
    }
    
}
